<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='txgl'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">

    <div class="layui-card">
        <div class="layui-field-box layui-form">
            <table class="layui-table" lay-size="sm">
                <thead>
                <tr>
                    <th><fmt:message key='xh'/></th>
                    <th><fmt:message key='sjmc'/></th>
                    <th><fmt:message key='sjdh'/></th>
                    <th><fmt:message key='sqje'/></th>
                    <th><fmt:message key='sqsj'/></th>
                    <th><fmt:message key='jssj'/></th>
                    <th><fmt:message key='jszt'/></th>
                    <th><fmt:message key='ptbz'/></th>
                    <th><fmt:message key='fpxx'/></th>
                    <th><fmt:message key='cz'/></th>
                </tr>
                </thead>

                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td>${status.index + 1}</td>
                        <td>${item.merchant.realName}</td>
                        <td>${item.merchant.mobile}</td>
                        <td><fmt:formatNumber value="${item.amount}" type="CURRENCY"/></td>
                        <td><fmt:formatDate value="${item.applyTime}" type="both"/></td>
                        <td><fmt:formatDate value="${item.finalTime}" type="both"/></td>
                        <td>
                            <c:choose>
                                <c:when test="${item.status eq 1}"><b style="color:blue"><fmt:message key='sqz'/></b></c:when>
                                <c:when test="${item.status eq 2}"><b style="color:orange"><fmt:message key='shtg'/></b></c:when>
                                <c:when test="${item.status eq 3}"><b style="color:red"><fmt:message key='shbtg'/></b></c:when>
                                <c:when test="${item.status eq 5}"><b style="color:blue"><fmt:message key='yjs'/></b></c:when>
                            </c:choose>
                        </td>
                        <td>${item.note}</td>
                        <td>
                            <c:if test="${not empty item.invoice}">
                                <c:forEach items="${fn:split(item.invoice, ';')}" var="image">
                                    <img src="${store_domain}/uploads/${image}" class="preview" style="width:40px;height:40px;"/>
                                </c:forEach>
                            </c:if>
                        </td>
                        <td>
                            <div class="layui-btn-container">
                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-detail"><fmt:message key='mx'/></a>

                                <c:choose>
                                    <c:when test="${item.status eq 1}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-process-allow"><fmt:message key='shtg'/></a>
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-process-reject"><fmt:message key='jj'/></a>
                                    </c:when>
                                    <c:when test="${item.status eq 2}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs layui-btn-danger feijin-finish"><fmt:message key='jswc'/></a>
                                    </c:when>
                                </c:choose>
                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    layui.use(['layer', 'form', 'laydate'], function () {
        var layer = layui.layer;

        //查看详情
        $(".feijin-detail").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 2
                , title: '<fmt:message key='ckjsdmx'/>'
                , content: '${web_domain}/mall/merchant/withdraw/' + id + '/detail'
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='fh'/>']
            });
        });

        //拒绝审核
        $(".feijin-process-reject").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 1
                , title: '<fmt:message key='jjly'/>'
                , content: '<br/><br/><div class="layui-form-item"><label class="layui-form-label"><fmt:message key='shbtgyy'/></label><div class="layui-input-block"><textarea id="reject-note" class="layui-input" style="width:300px;height:100px;"/></div></div>'
                , maxmin: true
                , area: ['80%', '80%']
                , btn: ['<fmt:message key='qd1'/>']
                , yes: function () {

                    $.ajax({
                        url: "${web_domain}/mall/merchant/withdraw/" + id + "/reject",
                        type: "post",
                        dataType: "json",
                        data: {
                            "note": $("#reject-note").val()
                        },
                        success: function (result) {
                            if (result.status) {
                                location.reload();
                            }
                        }
                    });

                }
            });

        });

        //通过审核
        $(".feijin-process-allow").click(function () {
            var id = $(this).attr("data-id");

            layer.confirm("<fmt:message key='qrtgshm?'/>", function () {
                $.ajax({
                    url: "${web_domain}/mall/merchant/withdraw/" + id + "/pass",
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (result.status) {
                            location.reload();
                        }
                    }
                });
            });

        });


        //结算
        $(".feijin-finish").click(function () {
            var id = $(this).attr("data-id");

            if (!confirm("<fmt:message key='qryzfjskxgsjlm?'/>")) {
                return false;
            }

            $.ajax({
                url: "${web_domain}/mall/merchant/withdraw/" + id + "/finish",
                type: "post",
                dataType: "json",
                success: function (result) {
                    if (result.status) {
                        location.reload();
                    }
                }
            });
        });

    });

</script>
</body>
</fmt:bundle>
</html>
